package com.ruoyi.work.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.ResponseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.Pages;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.work.domain.WorkBillKiln;
import com.ruoyi.work.service.IWorkBillKilnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * 窑烧工单详情Controller
 * 
 * @author xwj
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/system/workKiln")
@Api(tags = "窑烧工单详情")
public class WorkBillKilnController extends BaseController {
    @Autowired
    private IWorkBillKilnService workBillKilnService;

    /**
     * 查询窑烧工单详情列表
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public TableDataInfo list(@RequestBody WorkBillKiln workBillKiln) {
        startPage();
        List<WorkBillKiln> list = workBillKilnService.selectWorkBillKilnList(workBillKiln);
        return getDataTable(list);
    }

    @PostMapping("/listAll")
    @ApiOperation("不分页查询")
    public AjaxResult listAll(@RequestBody WorkBillKiln workBillKiln) {
        startOrderBy();
        List<WorkBillKiln> list = workBillKilnService.selectWorkBillKilnList(workBillKiln);
        return success(list);
    }

    /**
     * 导出窑烧工单详情列表
     */
    @Log(title = "窑烧工单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出")
    public void export(HttpServletResponse response, WorkBillKiln workBillKiln) {
        List<WorkBillKiln> list = workBillKilnService.selectWorkBillKilnList(workBillKiln);
        ExcelUtil<WorkBillKiln> util = new ExcelUtil<WorkBillKiln>(WorkBillKiln.class);
        util.exportExcel(response, list, "窑烧工单详情数据");
    }

    /**
     * 获取窑烧工单详情详细信息
     */
    @GetMapping(value = "/info/{id}")
    @ApiOperation("详情")
    public AjaxResult info(@PathVariable("id") Long id)  {
        return success(workBillKilnService.selectWorkBillKilnById(id));
    }

    /**
     * 新增窑烧工单详情
     */
    @Log(title = "窑烧工单详情", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增")
    public AjaxResult save(@RequestBody WorkBillKiln workBillKiln) {
        SysUser user = getLoginUser().getUser();
        if(workBillKiln.getId() == null) {
        workBillKiln.setCreateId(user.getUserId());
            workBillKiln.setCreateTime(DateUtils.getNowDate());
            workBillKiln.setCreateBy(user.getNickName());
            workBillKilnService.insertWorkBillKiln(workBillKiln);
        } else {
            workBillKiln.setUpdateId(user.getUserId());
            workBillKiln.setUpdateTime(DateUtils.getNowDate());
            workBillKiln.setUpdateBy(user.getNickName());
            workBillKilnService.updateWorkBillKiln(workBillKiln);
        }

        return success(workBillKiln);
    }

    /**
     * 修改窑烧工单详情
     */
    @Log(title = "窑烧工单详情", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改")
    public AjaxResult update(@RequestBody WorkBillKiln workBillKiln) {
        SysUser user = getLoginUser().getUser();
                workBillKiln.setUpdateId(user.getUserId());
                workBillKiln.setUpdateTime(DateUtils.getNowDate());
                workBillKiln.setUpdateBy(user.getNickName());
        return success(workBillKilnService.updateWorkBillKiln(workBillKiln));
    }

    /**
     * 删除窑烧工单详情
     */
    @Log(title = "窑烧工单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除或批量删除")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(workBillKilnService.deleteWorkBillKilnByIds(ids));
    }

    @Log(title = "窑烧工单详情", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @ApiOperation("条件删除")
    public ResponseModel delete(@RequestBody WorkBillKiln workBillKiln) {
        int num = workBillKilnService.delete(workBillKiln);
        return ResponseModel.of(num);
    }

    @PostMapping("/queryPage")
    @ApiOperation("分页查询-mp")
    public ResponseModel<Pages<WorkBillKiln>> queryPage(@RequestBody WorkBillKiln workBillKiln) {
        Pages<WorkBillKiln> page = workBillKilnService.queryPage(workBillKiln);
        return ResponseModel.of(page);
    }
}
